{% extends 'layout/manage.html' %}
{% load issues %}
{% load static %}
{% block title %}{% endblock %}

{% block css %}
    <link rel="stylesheet" href="{% static 'web/plugin/editor-md/css/editormd.min.css' %}">
    <link rel="stylesheet" href="{% static 'web/plugin/bootstrap-datepicker/css/bootstrap-datepicker.min.css' %}">
    <link rel="stylesheet" href="{% static 'web/plugin/bootstrap-select/css/bootstrap-select.min.css' %}">
    <link rel="stylesheet" href="{% static 'web/plugin/select2/css/select2.min.css' %}">

    <style>
        .switch {
            position: relative;
            display: inline-block;
            width: 60px;
            height: 34px;
        }

        .switch input {
            opacity: 0;
            width: 0;
            height: 17px;
        }

        .slider {
            position: absolute;
            cursor: pointer;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: #ccc;
            -webkit-transition: .4s;
            transition: .4s;
        }

        .slider:before {
            position: absolute;
            content: "";
            height: 26px;
            width: 26px;
            left: 4px;
            bottom: 4px;
            background-color: white;
            -webkit-transition: .4s;
            transition: .4s;
        }

        input:checked + .slider {
            background-color: #2196F3;
        }

        input:focus + .slider {
            box-shadow: 0 0 1px #2196F3;
        }

        input:checked + .slider:before {
            -webkit-transform: translateX(26px);
            -ms-transform: translateX(26px);
            transform: translateX(26px);
        }

        /* Rounded sliders */
        .slider.round {
            border-radius: 34px;
        }

        .slider.round:before {
            border-radius: 50%;
        }


        .story-list .number {
            width: 100px;
            text-align: right;
        }

        .story-list .number a {
            font-weight: 500;
            padding: 0 10px;
        }

        .story-list .issue .tags {
            padding: 10px 0;
        }

        .story-list .issue .tags span {
            margin-right: 20px;
            display: inline-block;
            font-size: 12px;
        }

        .story-list .issue .tags .type {
            color: white;
            padding: 1px 5px;
            border-radius: 5px;
            background-color: #dddddd;
        }

        .story-list .issue .tags .type_primary {
            color: white;
            padding: 1px 5px;
            border-radius: 5px;
            background-color: #007bff;
        }

        .story-list .issue .tags .type_warning {
            color: white;
            padding: 1px 5px;
            border-radius: 5px;
            background-color: #ffc107;
        }

        .story-list .issue .tags .type_success {
            color: white;
            padding: 1px 5px;
            border-radius: 5px;
            background-color: #28a745;
        }

        .story-list .issue .tags .type_danger {
            color: white;
            padding: 1px 5px;
            border-radius: 5px;
            background-color: #dc3545;
        }

        .story-list .issue .tags .type_info {
            color: white;
            padding: 1px 5px;
            border-radius: 5px;
            background-color: #17a2b8;
        }


        .editormd {
            margin-bottom: 0;
        }

        .pd-0 {
            padding: 0 !important;
        }

        /* 筛选 */
        .filter-area .item {
            margin-bottom: 15px;
        }

        .filter-area .item .title {
            padding: 5px 0;
        }

        .filter-area .item .check-list a {
            text-decoration: none;
            display: inline-block;
            min-width: 65px;
        }

        .filter-area .item .check-list label {
            font-weight: 200;
            font-size: 13px;
            margin-left: 3px;
        }

        .filter-area .item .check-list a:hover {
            font-weight: 300;
        }

        .filter-area .item .check-list .cell {
            margin-right: 10px;
        }
    </style>
{% endblock %}

{% block content %}
    <div class="container-fluid clearfix" style="padding: 20px 0;">
        <div class="col-sm-3">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <i class="fa fa-search" aria-hidden="true"></i>筛选
                    <label class="fa! switch">
                        <input type="checkbox" id="mytaskToggle" name="trigger"
                               onclick="mytaskTrigger()">
                        <span class="slider round"></span>
                    </label>
                    只看与我相关
                </div>
                <div class="panel-body filter-area">
                    {% for row in filter_list %}
                        <div class="item">
                            <div class="title">{{ row.title }}</div>
                            <div class="check-list">

                                {% for item in row.filter %}
                                    {{ item }}
                                {% endfor %}

                            </div>
                        </div>
                    {% endfor %}

                </div>
            </div>
        </div>
        <div class="col-sm-9">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <i class="fa fa-tasks" aria-hidden="true"></i> 需求/故事
                </div>
                <div class="col-md-12">
                    <div class="col-md-6">
                        <form method="get" action="{% url 'breakdownstory' project_id=request.web.project.id %}">
                            <div class="input-group">
                                 <span class="input-group-btn">
                         <button class="btn btn-default" type="submit">搜索</button>
                     </span>
                                <input type="text" name="q" class="form-control" placeholder="Search for..."
                                       value={{ value }}>
                                <span class="input-group-btn">
                         <button class="btn btn-default" type="submit">搜索</button>
                     </span>
                            </div>
                        </form>
                    </div>
                    <div class="col-md-6">
                        <ul class="nav nav-pills">
                            <li role="presentation" id="allLi"><a href="javascript:void(0)"
                                                                  onclick="searchAllTodoDone('all')">ALL</a></li>
                            <li role="presentation" id="todoLi"><a href="javascript:void(0)"
                                                                   onclick="searchAllTodoDone('todo')">TODO</a></li>
                            <li role="presentation" id="doneLi"><a href="javascript:void(0)"
                                                                   onclick="searchAllTodoDone('done')">DONE</a></li>
                        </ul>
                    </div>

                </div>


                <div class="panel-body">
                    <a id="addStory" class="btn btn-success btn-sm" data-toggle="modal"
                       data-target="">新建BreakdownStory</a>
                    {#                    <a class="btn btn-primary btn-sm" data-toggle="modal" data-target="#inviteModal">邀请成员</a>#}
                </div>

                <!-- Table -->
                <table class="table">
                    <tbody class="story-list">
                    {% for item in story_object_list %}
                        <tr>
                            <td class="number">
                                <i class="fa fa-circle text-{{ item.priority }}"></i>
                                <a target="_blank"
                                   href="{% url 'story_detail' project_id=request.web.project.id story_id=item.id %}">{% string_just item.id %}</a>
                            </td>
                            <td class="issue">
                                <div>
                                    <a target="_blank"
                                       href="{% url 'story_detail' project_id=request.web.project.id story_id=item.id %}">{{ item.story_name }}</a>
                                </div>
                                <div class="tags">
                                    <span class="{% if item.status == 1 %}
                                            type_primary
                                            {% elif item.status == 2 %}
                                             type_warning
                                            {% elif item.status == 3 or item.status == 9%}
                                            type_success
                                            {% elif item.status == 4 %}
                                            type_danger
                                            {% elif item.status == 5%}
                                            type_info
                                   {% else %}type{% endif %}">
                                        {{ item.story_type }}
                                    </span>
                                    <span>
                                        <i class="fa fa-refresh" aria-hidden="true"></i> {{ item.get_status_display }}
                                    </span>
                                    {% if item.milestone.name %}
                                        <span>
                                        <i class="fa fa-flag" aria-hidden="true"></i> {{ item.milestone.name }}
                                    </span>
                                    {% endif %}


                                    {% if item.module %}
                                        <span>
                                        <i class="fa fa-key" aria-hidden="true"></i> {{ item.module }}
                                    </span>
                                    {% endif %}
                                    {#                                    {% if item.assign.username %}#}
                                    {#                                        <span>#}
                                    {#                                        <i class="fa fa-hand-o-right" aria-hidden="true"></i>#}
                                    {#                                        {{ item.assign.username }}#}
                                    {#                                    </span>#}
                                    {#                                    {% endif %}#}
                                    <span>
                                        <i class="fa fa-user-o" aria-hidden="true"></i>
                                        {{ item.creator.username }}
                                    </span>
                                    {% if item.end_date %}
                                        <span>
                                        <i class="fa fa-calendar" aria-hidden="true"></i>
                                        {{ item.end_date }} 截止
                                    </span>
                                    {% endif %}
                                    <span>
                                        <i class="fa fa-clock-o" aria-hidden="true"></i>
                                        {{ item.latest_update_datetime }} 更新
                                    </span>
                                    {% if item.using_time %}
                                        <span>
                                        <i class="fa fa-clock-o" aria-hidden="true"></i>
                                        {{ item.using_time }} 用时
                                    </span>
                                    {% endif %}
                                    {% if request.web.user == request.web.project.creator %}
                                        <a href="javascript:void(0);"
                                           onclick="del({{ item.id }})"
                                           style="float:right">[删除]</a>
                                    {% endif %}
                                </div>

                            </td>

                        </tr>
                    {% endfor %}
                    </tbody>
                </table>
            </div>
            <nav aria-label="...">
                <ul class="pagination" style="margin-top: 0px">
                    {{ page_html|safe }}
                </ul>
            </nav>

        </div>

    </div>

    <div id="addModal" class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog"
         aria-labelledby="myLargeModalLabel">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">新建BreakdownStory</h4>
                </div>
                <div class="modal-body" style="padding-right: 40px;">

                    <form id="addForm" class="form-horizontal">
                        {% csrf_token %}
                         <div class="form-group">
                            <label for="{{ form.story_name.id_for_label }}"
                                   class="col-md-2 control-label">{{ form.story_name.label }}</label>
                            <div class="col-md-10">
                                <div>
                                    <div>
                                        {{ form.story_name }}
                                    </div>
                                    <div class="error-msg"></div>
                                </div>
                                <div class="error-msg"></div>
                            </div>
                        </div>


                        <div class="form-group">
                            <label for="{{ form.story_type.id_for_label }}"
                                   class="col-md-2 control-label">{{ form.story_type.label }}</label>
                            <div class="col-md-4">
                                <div>
                                    <div>
                                        {{ form.story_type }}
                                    </div>
                                    <div class="error-msg"></div>
                                </div>
                                <div class="error-msg"></div>
                            </div>
                                <label for="{{ form.version.id_for_label }}"
                                       class="col-md-2 control-label">{{ form.version.label }}</label>
                                <div class="col-md-4">

                                    {{ form.version }}

                                    <div class="error-msg"></div>
                                </div>
                        </div>

                        <div class="form-group">
                            <label for="{{ form.module.id_for_label }}"
                                   class="col-md-2 control-label">{{ form.module.label }}</label>
                            <div class="col-md-4">
                                <div>
                                    <div>
                                        {{ form.module }}
                                    </div>
                                    <div class="error-msg"></div>
                                </div>
                                <div class="error-msg"></div>
                            </div>
                            <label for="{{ form.milestone.id_for_label }}"
                                   class="col-md-2 control-label">{{ form.milestone.label }}</label>
                                <div class="col-md-4">

                                    {{ form.milestone }}

                                    <div class="error-msg"></div>
                                </div>
                        </div>
                        <div class="form-group">
                            <label for="{{ form.description.id_for_label }}"
                                   class="col-md-2 control-label">{{ form.description.label }}</label>
                            <div class="col-md-10">
                                <div>
                                    <div id="editor">
                                        {{ form.description }}
                                    </div>

                                    <div class="error-msg"></div>
                                </div>
                                <div class="error-msg"></div>
                            </div>
                        </div>


                        <div class="form-group">
                            <label for="{{ form.acceptance_criteria.id_for_label }}"
                                   class="col-md-2 control-label">{{ form.acceptance_criteria.label }}</label>
                            <div class="col-md-10">
                                <div>
                                    <div id="editor1">
                                        {{ form.acceptance_criteria }}
                                    </div>

                                    <div class="error-msg"></div>
                                </div>
                                <div class="error-msg"></div>
                            </div>
                        </div>

                        <div class="form-group clearfix">

                            <div class="col-md-6 pd-0">
                                <label for="{{ form.status.id_for_label }}"
                                       class="col-md-4 control-label">{{ form.status.label }}</label>
                                <div class="col-md-8 clearfix">
                                    <div>
                                        {{ form.status }}
                                    </div>
                                    <div class="error-msg"></div>

                                </div>
                            </div>
                            <div class="col-md-6 pd-0">
                                <label for=" {{ form.priority.id_for_label }}"
                                       class="col-md-4 control-label">{{ form.priority.label }}</label>
                                <div class="col-md-8">
                                    <div>
                                        {{ form.priority }}
                                    </div>
                                    <div class="error-msg"></div>

                                </div>
                            </div>
                        </div>

                        <div class="form-group clearfix">
                            <div class="col-md-6 pd-0">
                                <label for="inputPassword3" class="col-md-4 control-label">指派给</label>
                                <div class="col-md-8">
                                    {{ form.assign }}
                                    <div class="error-msg"></div>
                                </div>
                            </div>

                            <div class="col-md-6 pd-0">
                                <label for="inputPassword3" class="col-md-4 control-label">关注者</label>
                                <div class="col-md-8">

                                    {{ form.attention }}

                                    <div class="error-msg"></div>
                                </div>
                            </div>

                        </div>

                        <div class="form-group clearfix">
                            <div class="col-md-6 pd-0">
                                <label for="inputPassword3" class="col-md-4 control-label">开始时间</label>
                                <div class="col-md-8">

                                    <div class="input-group">
                                        <span class="input-group-addon" id="sizing-addon2">
                                            <i class="fa fa-calendar" aria-hidden="true"></i>
                                        </span>
                                        {{ form.start_date }}
                                    </div>
                                    <span class="error-msg"></span>

                                </div>
                            </div>

                            <div class="col-md-6 pd-0">
                                <label for="inputPassword3" class="col-md-4 control-label">截止时间</label>
                                <div class="col-md-8">

                                    <div class="input-group">
                                        <span class="input-group-addon" id="sizing-addon2">
                                            <i class="fa fa-calendar" aria-hidden="true"></i>
                                        </span>
                                        {{ form.end_date }}
                                    </div>
                                    <span class="error-msg"></span>
                                </div>
                            </div>
                        </div>
                        <div class="form-group clearfix">
                            {% comment %}   <div class="col-md-6 pd-0">
                                <label for="inputPassword3" class="col-md-4 control-label">模式</label>
                                <div class="col-md-8">
                                    <div>
                                        {{ form.mode }}
                                    </div>
                                    <div class="error-msg"></div>
                                </div>
                            </div>{% endcomment %}

                            <div class="col-md-6 pd-0">
                                <label for="inputPassword3" class="col-md-4 control-label"> 父需求</label>
                                <div class="col-md-8">
                                    {{ form.parent }}

                                    <div class="error-msg"></div>
                                </div>
                            </div>
                                 <div class="col-md-6 pd-0">
                               <label for="{{ form.iteration_number.id_for_label }}"
                                   class="col-md-4 control-label">{{ form.iteration_number.label }}</label>
                                <div class="col-md-8">

                                    {{ form.iteration_number }}

                                    <div class="error-msg"></div>
                                </div>
                                 </div>
                        </div>

                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取 消</button>
                    <button type="button" class="btn btn-primary" id="btnAddSubmit">添 加</button>
                </div>
            </div>
        </div>
    </div>



    <div class="modal fade in" id="inviteModal" role="dialog">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">邀请成员</h4>
                </div>
                <div class="modal-body" style="padding-right: 40px;">
                    <form id="inviteForm">
                        {% csrf_token %}
                        {% for item in invite_form %}
                            <div class="form-group">
                                <label for="{{ item.id_for_label }}">{{ item.label }}</label>
                                <span>{% if  item.help_text %}（{{ item.help_text }}）{% endif %}</span>
                                {{ item }}
                                <span class="error-msg"></span>
                            </div>
                        {% endfor %}
                        <button type="button" class="btn btn-success" id="btnGenInviteCode">生成邀请码</button>
                    </form>
                    <div id="inviteArea" class="hide">
                        <hr/>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-btn">
                                    <input type="button" value="邀请链接" class="btn btn-default">
                                </div>
                                <input type="text" class="form-control" id="inviteUrl">
                                <div class="input-group-btn">
                                    <input type="button" value="复制链接" class="btn btn-primary" id="btnCopyUrl">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>

    <input id="csrf_token" value="{{ csrf_token }}" hidden="hidden"/>
    <input id="user_id" value="{{ request.web.user.id }}" hidden="hidden"/>
    <input id="project_id" value="{{ request.web.project.id }}" hidden="hidden"/>
    <input id="username" value="{{ request.web.user.username }}" hidden="hidden"/>

{% endblock %}

{% block js %}
    <script src="{% static 'web/plugin/editor-md/editormd.min.js' %}"></script>
    <script src="{% static 'web/plugin/bootstrap-datepicker/js/bootstrap-datepicker.min.js' %}"></script>
    <script src="{% static 'web/plugin/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js' %}"></script>
    <script src="{% static 'web/plugin/bootstrap-select/js/bootstrap-select.min.js' %}"></script>
    <script src="{% static 'web/plugin/bootstrap-select/js/i18n/defaults-zh_CN.min.js' %}"></script>
    <script src="{% static 'web/plugin/select2/js/select2.min.js' %}"></script>
    <script src="{% static 'web/plugin/select2/js/i18n/zh-CN.js' %}"></script>

    <script>
        var WIKI_UPLOAD_URL = "{% url 'wiki_upload' project_id=request.web.project.id %}";
        var POST_STORY = "{% url 'breakdownstory' project_id=request.web.project.id %}";
        var INVITE_URL = "{% url 'invite_url' project_id=request.web.project.id %}";

        const mystoryTriggerKey = "mystoryTrigger" + '{{ request.web.user.id }}' + '_' + '{{ request.web.project.id }}'
        console.log('mystoryTriggerKey', mystoryTriggerKey)
        var user_id = eval(document.getElementById("user_id").value);
        var project_id = eval(document.getElementById("project_id").value);
        var username = document.getElementById("username").value;
        $(function () {
            bindBootStrapShowEvent();
            initDatePicker();
            bindAddSubmit();
            bindClickCheckFilter();
            initSelect2();
            bindCreateInviteCode();
            bindCopyUrl();
            // 获取a标签元素
            const addStory = document.getElementById('addStory');
            $.ajax({
                url: "{% url 'has_milestone' project_id=request.web.project.id %}",
                type: "GET",
                success: function (res) {
                    if (res.status) {
                        addStory.setAttribute("data-target", "#addModal")

                    } else {

                        layui.use(function () {
                            var layer = layui.layer;
                            // Welcome
                            layer.msg('请先设置【迭代】- 里程碑', {icon: 6});
                        });
                        addStory.setAttribute("data-target", "")
                        event.preventDefault();  // 阻止默认事件
                        {#window.location.reload()#}
                    }
                }
            })

            // 监听点击事件
            addStory.addEventListener('click', (event) => {
                $.ajax({
                    url: "{% url 'has_milestone' project_id=request.web.project.id %}",
                    type: "GET",
                    success: function (res) {
                        if (res.status) {
                            addStory.setAttribute("data-target", "#addModal")

                        } else {

                            layui.use(function () {
                                var layer = layui.layer;
                                // Welcome
                                layer.msg('请先设置【迭代】- 里程碑', {icon: 6});
                            });
                            addStory.setAttribute("data-target", "")
                            event.preventDefault();  // 阻止默认事件
                            {#window.location.reload()#}
                        }
                    }
                })

            });

        });


        /**
         * 点击拷贝链接url
         * */
        function bindCopyUrl() {
            $('#btnCopyUrl').click(function () {
                var textInput = $('#inviteUrl')[0]; // document.getElementById('inviteUrl')
                textInput.select();
                document.execCommand("Copy");
                layui.use(function () {
                    var layer = layui.layer;
                    // Welcome
                    layer.msg('复制成功', {icon: 6});
                });
            })
        }

        /**
         *       点击生成邀请链接
         */
        function bindCreateInviteCode() {
            $('#btnGenInviteCode').click(function () {
                $('.error-msg').empty();
                $.ajax({
                    url: INVITE_URL,
                    type: "POST",
                    data: $('#inviteForm').serialize(),
                    dataType: "JSON",
                    success: function (res) {
                        if (res.status) {
                            $('#inviteArea').removeClass('hide').find('#inviteUrl').val(res.data);
                        } else {
                            $.each(res.error, function (k, v) {
                                $('#id_' + k).next('.error-msg').text(v[0]);
                            })
                        }
                    }
                })
            })
        }


        /**
         * 初始化select2
         * */
        function initSelect2() {
            $('.select2').select2().on('select2:select', function (e) {
                //select2选中事件
                location.href = e.params.data.id;
            }).on('select2:unselect', function (e) {
                //select2移除事件
                location.href = e.params.data.id;
            })
        }

        /**
         *
         * 绑定筛选器选择框
         */
        function bindClickCheckFilter() {
            $('.filter-area').find(':checkbox').click(function () {
                location.href = $(this).parent().attr('href');
            })
        }

        /**
         *
         * 初始化时间选择器
         * */
        function initDatePicker() {
            $('#id_start_date,#id_end_date').datepicker({
                format: 'yyyy-mm-dd',
                startDate: '0',
                language: 'zh-CN',
                autoclose: true
            })
        }

        function bindBootStrapShowEvent() {
            $("#addModal").on('shown.bs.modal', function (event) {
                initEditorMd();
            });
        }

        /**
         * 初始化markdown编辑器
         */
        function initEditorMd() {
            editormd('editor', {
                placeholder: "请输入内容",
                height: 300,
                path: "{% static 'web/plugin/editor-md/lib/' %}",
                imageUpload: true,
                imageFormats: ['jpg', 'jpeg', 'png', 'gif'],
                imageUploadURL: WIKI_UPLOAD_URL,
            })
        }

        function bindAddSubmit() {
            $('#addForm').find('.error-msg').empty();
            $('#btnAddSubmit').click(function () {
                $.ajax({
                    url: POST_STORY,
                    type: 'POST',
                    data: $('#addForm').serialize(),
                    dataType: 'JSON',
                    success: function (res) {
                        if (res.status) {
                            location.href = location.href
                        } else {
                            //错误信息
                            $.each(res.error, function (k, v) {
                                $('#id_' + k).parent().next('.error-msg').text(v[0]);
                            });
                        }
                    }
                })
            })
        }

        function mystoryTrigger() {
            console.log("mystoryTrigger")
            let isChecked = $('input[type="checkbox"][name="trigger"]').prop('checked');
            if (isChecked) {
                console.log("勾选");
                localStorage.setItem((user_id + '_' + project_id) + mystoryTriggerKey, "on")
            } else {
                console.log("未勾选");
                localStorage.setItem((user_id + '_' + project_id) + mystoryTriggerKey, "off")
            }
            sendFreshTriggerVal()

        }


        function sendFreshTriggerVal() {
            {#let csrf = {{ csrf_token }}#}
            $.ajax({
                url: "{% url 'cache' project_id=request.web.project.id %}",
                type: "POST",
                data: {
                    "trigger": localStorage.getItem((user_id + '_' + project_id) + mystoryTriggerKey),
                    "csrfmiddlewaretoken": $("#csrf_token").val()
                },
                dataType: "JSON",
                success: function (res) {
                    console.log(res);
                    if (res.code) {
                        console.log("reload")
                        location.reload();
                    } else {

                    }
                }

            })
        }

        function hasMilestone() {
            $.ajax({
                url: "{% url 'has_milestone' project_id=request.web.project.id %}",
                type: "GET",
                success: function (res) {
                    console.log('res', res)
                    if (res.status) {

                    } else {
                        layui.use(function () {
                            var layer = layui.layer;
                            // Welcome
                            layer.msg('请先设置【迭代】- 里程碑', {icon: 6});
                        });
                        {#window.location.reload()#}
                    }
                }
            })
        }

        function storageTriggerInit() {
            let item = localStorage.getItem((user_id + '_' + project_id) + mystoryTriggerKey);
            if (!item) {
                item = 'off'
                localStorage.setItem((user_id + '_' + project_id) + mystoryTriggerKey, item);
            } else {
                console.log("trigger", item)
                if (item == "on") {
                    $('input[type="checkbox"][name="trigger"]').prop('checked', true);
                } else {
                    $('input[type="checkbox"][name="trigger"]').prop('checked', false);
                }
            }
        }

        storageTriggerInit()

        function del(story_id) {
            layer.confirm('CONFIRM TO DELETE THIS STORY?', {btn: ['确定', '关闭']}, function () {
                $.ajax({
                    url: "{% url 'story_del' project_id=request.web.project.id %}",
                    type: "POST",
                    data: {
                        'story_id': story_id,
                        "csrfmiddlewaretoken": $("#csrf_token").val()
                    },
                    dataType: "JSON",
                    success: function (res) {
                        if (res.status) {
                            console.log(res.status)
                            window.location.reload()
                        } else {

                        }
                    }
                })
            }, function () {
            });
        }

        function searchAllTodoDone(type) {
            if (type == 'all') {
                window.location.href = "/manage/" + project_id + "/breakdownstory/?status=1&status=2&status=3&status=4&status=5&status=6&status=7&status=8&status=9" +
                    "&story_type=1&story_type=2&story_type=3&story_type=4" + '&priority=1&priority=2&priority=3&priority=4&priority=5'
            } else if (type == 'todo') {
                window.location.href = "/manage/" + project_id + "/breakdownstory/?status=1&status=2&status=3&status=4&status=5&status=9" +
                    "&story_type=1&story_type=2&story_type=3&story_type=4" + '&priority=1&priority=2&priority=3&priority=4&priority=5'
            } else if (type == 'done') {
                window.location.href = "/manage/" + project_id + "/breakdownstory/?status=6&status=7&status=8" +
                    "&story_type=1&story_type=2&story_type=3&story_type=4" + '&priority=1&priority=2&priority=3&priority=4&priority=5'
            }
        }


    </script>
{% endblock %}